#include<iostream>
#include<ctime>
#include<cstdlib>
using namespace std;

int main()
{
    cout << "请输入转置矩阵的行数和列数:\n";
    int n,m;
    cin >> n >> m ;
    srand(time(0));

    int A[n][m];
    int B[m][n];

    //初始化A B矩阵
    for(int i = 0;i < n;i++)
        for(int j = 0;j < m;j++)
        {
            //从0-100随机赋值
            A[i][j] = rand()%101;
            B[j][i] = rand()%101;
        }

    //输出A矩阵
    for(int i = 0;i < n;i++){
        for(int j = 0;j < m;j++)
            cout << A[i][j] << " ";
        cout << endl;     
    }

    //转置矩阵
     for(int i = 0;i < n;i++)
        for(int j = 0;j < m;j++)
        {
            B[j][i]  = A[i][j]; 
        }
    
    //输出转置后的结果B矩阵
     for(int i = 0;i < m;i++){
        for(int j = 0;j < n;j++)
            cout << B[i][j] << " ";
        cout << endl;     
    }
        
    return 0;
}